<template>
    <div class="app-container">
        <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" label-width="68px">
            <el-form-item label="单元号" prop="unit_num">
                <el-input v-model="queryParams.unit_num" placeholder="请输入单元号" clearable style="width: 240px"
                    @keyup.enter.native="handleQuery" />
            </el-form-item>
            <el-form-item label="社区id" prop="dept_id">
                <el-input v-model="queryParams.dept_id" placeholder="请输入社区id" clearable style="width: 240px"
                    @keyup.enter.native="handleQuery" />
            </el-form-item>
            <el-form-item label="产权人" prop="owner">
                <el-input v-model="queryParams.owner" placeholder="请输入产权人姓名" clearable style="width: 240px"
                    @keyup.enter.native="handleQuery" />
            </el-form-item>
            <el-form-item>
                <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
                <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
            </el-form-item>
        </el-form>
        <el-row :gutter="10" class="mb8">
            <el-col :span="1.5">
                <el-button type="primary" plain icon="el-icon-plus" size="mini" @click="handleAdd"
                    v-hasPermi="['house:house:add']">新增</el-button>
            </el-col>
            <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
        </el-row>

        <el-table v-loading="loading" :data="houseList">
            <el-table-column label="单元号" align="center" prop="unit_num" />
            <el-table-column label="门牌号" align="center" prop="house_num" />
            <el-table-column label="建筑面积" align="center" prop="build_area" />
            <el-table-column label="使用面积" align="center" prop="usable_area" />
            <el-table-column label="房产类别" align="center" prop="type">
                <template slot-scope="scope">
                    <dict-tag :options="dict.type.sys_house_type" :value="scope.row.type" />
                </template>
            </el-table-column>
            <el-table-column label="产权人" align="center" prop="owner" />
            <el-table-column label="身份证号" align="center" prop="idcard" />
            <el-table-column label="联系方式" align="center" prop="tel" />
            <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
                <template slot-scope="scope">
                    <el-button size="mini" type="text" icon="el-icon-edit" @click="handleUpdate(scope.row)"
                        v-hasPermi="['house:house:edit']">修改 </el-button>
                    <el-button size="mini" type="text" icon="el-icon-delete" @click="handleDelete(scope.row)"
                        v-hasPermi="['house:house:remove']">删除 </el-button>
                </template>
            </el-table-column>
        </el-table>
        <pagination v-show="total>0" :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize"
            @pagination="getList" />

        <el-dialog title="提示" :visible.sync="dialogVisible" width="600px" append-to-body>
            <el-form ref="form" :model="form" label-width="80px">
                <el-form-item label="单元号">
                    <el-input v-model="form.unit_num" placeholder="请输入单元号" />
                </el-form-item>
                <el-form-item label="门牌号">
                    <el-input v-model="form.house_num" placeholder="请输入门牌号" />
                </el-form-item>
                <el-form-item label="建筑面积">
                    <el-input v-model="form.build_area" placeholder="请输入建筑面积" />
                </el-form-item>
                <el-form-item label="使用面积">
                    <el-input v-model="form.usable_area" placeholder="使用面积" />
                </el-form-item>
                <el-form-item label="房产类别">
                    <el-select v-model="form.type" placeholder="请选择房产类别">
                        <el-option v-for="dict in dict.type.sys_house_type" :key="dict.value" :label="dict.label"
                          :value="dict.value"></el-option>
                      </el-select>
                </el-form-item>
                <el-form-item label="产权人">
                    <el-input v-model="form.owner" placeholder="请输入产权人"></el-input>
                </el-form-item>
                <el-form-item label="身份证号">
                    <el-input v-model="form.idcard" placeholder="请输入身份证号"></el-input>
                </el-form-item>
                <el-form-item label="联系电话">
                    <el-input v-model="form.tel" placeholder="请输入联系电话"></el-input>
                </el-form-item>
            </el-form>
            <span slot="footer" class="dialog-footer">
                <el-button type="primary" @click="submitForm">确 定</el-button>
                <el-button @click="cancel">取 消</el-button>
            </span>
        </el-dialog>
    </div>
</template>
<script>
    import { selectHouseList, addHouse, updateHouse, deleteById } from "@/api/house/house";
    export default {
        name: "house",
        dicts: ["sys_house_type"],
        data() {
            return {
                showSearch: true,
                loading: true,
                total: 0,
                queryParams: {
                    pageNum: 1,
                    pageSize: 10,
                    unit_num: undefined,
                    dept_id: undefined,
                    owner: undefined
                },
                ids: [],
                dialogVisible: false,
                form: {
                    id: undefined,
                    unit_num: undefined,
                    house_num: undefined,
                    build_area: undefined,
                    usable_area: undefined,
                    type: undefined,
                    building_id: undefined,
                    dept_id: undefined,
                    owner: undefined,
                    idcard: undefined,
                    tel: undefined,
                    create_by: undefined,
                    create_time: undefined,
                    update_by: undefined,
                    update_time: undefined,
                    remark: undefined,
                    user_id: undefined
                },
                houseList: [],
                rules: {},
            }

        },
        created() {
            this.getList();
        },
        methods: {
            // 模糊查询
            handleQuery() {
                this.queryParams.pageNum = 1;
                this.getList();
            },
            /** 重置按钮操作 */
            resetQuery() {
                this.queryParams = {
                    pageNum: 1,
                    pageSize: 10,
                    unit_num: undefined,
                    dept_id: undefined,
                    owner: undefined
                };
                this.resetForm("queryForm");
                this.handleQuery();
            },
            getList() {
                selectHouseList(this.queryParams).then(response => {
                    this.houseList = response.rows;
                    this.total = response.total;
                    this.loading = false;
                }

                );
            },
            // 取消按钮
            cancel() {
                this.dialogVisible = false;
                this.reset();
            },
            /** 新增按钮操作 */
            handleAdd(row) {
                this.reset();
                this.dialogVisible = true;
            },
            // 修改
            handleUpdate(row) {
                this.reset();
                this.dialogVisible = true;
                this.form = row;
            },
            // 删除
            handleDelete(row) {
                const id = row.id;
                this.$modal.confirm('是否确认删除学生编号为"' + id + '"的数据项？').then(function () {
                    return deleteById(id);
                }).then(() => {
                    this.getList();
                    this.$modal.msgSuccess("删除成功");
                }).catch(() => { });
            },
            reset() {
                this.form = {
                    id: undefined,
                    unit_num: undefined,
                    house_num: undefined,
                    build_area: undefined,
                    usable_area: undefined,
                    type: undefined,
                    building_id: undefined,
                    dept_id: undefined,
                    owner: undefined,
                    idcard: undefined,
                    tel: undefined,
                    create_by: undefined,
                    create_time: undefined,
                    update_by: undefined,
                    update_time: undefined,
                    remark: undefined,
                    user_id: undefined
                };
                this.resetForm("form");
            },
            /** 提交按钮 */
            submitForm: function () {
                if (this.form.id !== undefined) {
                    updateHouse(this.form).then(response => {
                        this.$modal.msgSuccess("修改成功");
                        this.dialogVisible = false;
                        this.getList();
                    });
                } else {
                    addHouse(this.form).then(response => {
                        this.$modal.msgSuccess("新增成功");
                        this.dialogVisible = false;
                        this.getList();
                    });
                }
            },
        }
    }
</script>

<style scoped>

</style>